
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel=stylesheet href='include/hoj.css' type='text/css'>
</head>
<body>
<center>
<div style="width:90%; text-align:left">
<img src="image/logo.png"/>
</div>
<table width=96%> 
	<tr align="center" class='hd' valign="top">
				<th><a href="faqs.php">F.A.Qs</a></th>
		<th><a href="./bbs.php">Web Board</a></th>
		<th><a href="./">Home</a></th>
		<th><a href="./problemset.html">ProblemSet</a></th>
		<th><a href="./status.php">Status</a></th>
		<th><a href="./ranklist.php">Ranklist</a></th>
		<th><a href="./contest.php">Contest</a></th>
		<th><a href=loginpage.php>Login</a></th><th><a href=registerpage.php>Register</a></th>	</tr>
</table>
</center>
<center>
<div class="notice">
	<div>
		<B>Notice:</B>鉴于种种原因，本OJ自下周星期一（3月5号）开始不再全面开放，请各位做好善后事宜，谢谢合作。	</div>
</div>
</center>
</div>
<title>Problem 1738. -- [Usaco2005 mar]Ombrophobic Bovines -- 衡阳八中OJ离线版-2012-02-29</title><center><h2>1738: [Usaco2005 mar]Ombrophobic Bovines</h2><span class=green>Time Limit: </span>5 Sec&nbsp;&nbsp;<span class=green>Memory Limit: </span>64 MB<br><span class=green>Submit: </span>48&nbsp;&nbsp;<span class=green>Solved: </span>23<br>[<a href='submitpage.php?id=1738'>Submit</a>][<a href='problemstatus.php?id=1738'>Status</a>][<a href='bbs.php?id=1738'>Discuss</a>]</center><h2>Description</h2><div class=content>
FJ's cows really hate getting wet so much that the mere thought of
getting caught in the rain makes them shake in their hooves.  They
have decided to put a rain siren on the farm to let them know when
rain is approaching. They intend to create a rain evacuation plan
so that all the cows can get to shelter before the rain begins.
Weather forecasting is not always correct, though. In order to
minimize false alarms, they want to sound the siren as late as
possible while still giving enough time for all the cows to get to
some shelter.

The farm has F (1 <= F <= 200) fields on which the cows graze.  A
set of P (1 <= P <= 1500) paths connects them. The paths are wide,
so that any number of cows can traverse a path in either direction.

Some of the farm's fields have rain shelters under which the cows
can shield themselves. These shelters are of limited size, so a
single shelter might not be able to hold all the cows.  Fields are
small compared to the paths and require no time for cows to traverse.

Compute the minimum amount of time before rain starts that the siren
must be sounded so that every cow can get to some shelter.

</div><h2>Input</h2><div class=content>
* Line 1: Two space-separated integers: F and P

* Lines 2..F+1: Two space-separated integers that describe a field. 
        The first integer (range: 0..1000) is the number of cows in
        that field.  The second integer (range: 0..1000) is the number
        of cows the shelter in that field can hold.  Line i+1
        describes field i.

* Lines F+2..F+P+1: Three space-separated integers that describe a
        path. The first and second integers (both range 1..F) tell the
        fields connected by the path. The third integer (range:
        1..1,000,000,000) is how long any cow takes to traverse it.

</div><h2>Output</h2><div class=content>
* Line 1: The minimum amount of time required for all cows to get
        under a shelter, presuming they plan their routes optimally. 
        If it not possible for the all the cows to get under a
        shelter, output "-1".

</div><h2>Sample Input</h2>
			<div class=content><span class=sampledata><br />
3 4<br />
7 2<br />
0 4<br />
2 6<br />
1 2 40<br />
3 2 70<br />
2 3 90<br />
1 3 120<br />
<br />
</span></div><h2>Sample Output</h2>
			<div class=content><span class=sampledata><br />
110<br />
<br />
OUTPUT DETAILS:<br />
<br />
In 110 time units, two cows from field 1 can get under the shelter in that<br />
field, four cows from field 1 can get under the shelter in field 2, and one<br />
cow can get to field 3 and join the cows from that field under the<br />
shelter in field 3.  Although there are other plans that will get all the<br />
cows under a shelter, none will do it in fewer than 110 time units.</span></div><h2>HINT</h2>
			<div class=content><p></p></div><h2>Source</h2>
			<div class=content><p><a href='problemset.html?search=Gold'>Gold</a></p></div><center>[<a href='submitpage.php?id=1738'>Submit</a>][<a href='problemstatus.php?id=1738'>Status</a>][<a href='bbs.php?id=1738'>Discuss</a>]</center>﻿<br>

<a href="./"><span class=red>HOME</span></a>
<a href="javascript:history.go(-1)"><span class=red>Back</span></a>

<hr>
<center>
	<div class="footer">
			<a href=setlang.php?lang=ko>한국어</a>&nbsp;
		<a href=setlang.php?lang=cn>中文</a>&nbsp;
		<a href=setlang.php?lang=fa>فارسی</a>&nbsp;
		<a href=setlang.php?lang=en>English</a>&nbsp;
		<a href=setlang.php?lang=th>ไทย</a>
	<br>		<div>版权所有 &copy;2008-2012 WaterPark Organization. | <script src="http://s21.cnzz.com/stat.php?id=2982771&web_id=2982771" language="JavaScript"></script>
</div>
		<div>Based on opensource project <a href="http://hustoj.googlecode.com">hustoj</a>.</div>
	</div>
</center>
</body>
</html>
